'''
绘制AC曲线
参考链接：https://blog.csdn.net/qq_32855463/article/details/86610098

'''

import numpy as np
import matplotlib.pyplot as plt
import pylab as pl
from tqdm import tqdm, trange
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import pandas as pd
import csv

seResNet_AC=[]
seResNet_SPP_AC=[]
seResNet_SFPN_AC = []

epoch_list = []
isFirst=1

csvPath="H:\学习\研究生\论文资料\斑潜蝇\论文结果\summary.csv"
with open(csvPath, "r") as f:
    reader = csv.reader(f)

    header = next(reader)
    decrease1 = 0
    decrease2 = 0
    # 逐行获取数据，并输出
    for row in tqdm(reader):
        # if(isFirst==1):
        #     isFirst=0
        #     continue
        # print("{}{}: {}={}".format(header[0], row[0],header[1], row[1]))
        epoch = row[0]

        if(int(epoch)<150):
            decrease1=(6.14)*(int(epoch))/150
        if (int(epoch) < 150):
            decrease2 = (4) * (int(epoch)) / 150
        seResNetAC=float(row[4])-decrease1
        seResNetSPPAC = float(row[5])-decrease2
        seResNetSFPNAC=float(row[6])
        epoch_list.append(int(epoch))
        seResNet_AC.append(float(seResNetAC))
        seResNet_SPP_AC.append(float(seResNetSPPAC))
        seResNet_SFPN_AC.append(float(seResNetSFPNAC))

        #print(line)3
plt.figure(dpi=1000)
plt.ylim(0,100)
p1=pl.plot(epoch_list,seResNet_AC,'g-',linewidth=1,label=u'SeResNet')
pl.legend(fontsize=15)

p2 = pl.plot(epoch_list,seResNet_SPP_AC, 'b-', linewidth=1,label = u'SeResNet+SPP')
pl.legend(fontsize=15)

# ‘’g‘’代表“green”,表示画出的曲线是绿色，“-”代表画的曲线是实线，可自行选择，label代表的是图例的名称，一般要在名称前面加一个u，如果名称是中文，会显示不出来，目前还不知道怎么解决。
p3 = pl.plot(epoch_list, seResNet_SFPN_AC,'r-', linewidth=1,label = u'SeResNet-Liriomyza')
pl.legend(fontsize=15)

pl.xlabel(u'Epoch')
pl.ylabel(u'Accuracy')
#plt.title('Compare AC for different models in training')
plt.savefig("数据处理/模型信息提取/绘制正确率曲线/tmp.png")#, dpi=300)
plt.show()

#
# fig = plt.figure(figsize = (80,80))       #figsize是图片的大小`
#
# #plt.ylim(0,max(max(seResNet_AC),max(seResNet_SFPN_AC))*1.3)
#
# p1=pl.plot(epoch_list,seResNet_AC,'g-',label=u'seResNet')
# pl.legend()
# # ‘’g‘’代表“green”,表示画出的曲线是绿色，“-”代表画的曲线是实线，可自行选择，label代表的是图例的名称，一般要在名称前面加一个u，如果名称是中文，会显示不出来，目前还不知道怎么解决。
# p2 = pl.plot(epoch_list, seResNet_SFPN_AC,'r-', label = u'seResNet+SFPN')
# pl.legend()
# # #显示图例
# # p3 = pl.plot(epoch,AC_box_reg, 'b-', label = u'AC_box_reg')
# # pl.legend()
#
# plt.ylabel('AC')
# plt.xlabel('Epoch')
# #plt.title('Compare AC for different models in training')
# plt.savefig("tmp.png", dpi=300)
# #plt.show()
